﻿var Print_Main = '';

Ext.define('HIT.view.DealPrintComplexSearchPanel', {
    extend: 'Ext.form.Panel',
    alias: 'widget.printcomplexsearchpanel',
//排序字段panel
    anchor: '100%',
    margin: '10 0 10',
    height: 24,
    frame:false,
    layout: {
        type: 'absolute'
    },
    
    initComponent: function() {
        var me = this;
        Ext.namespace("mul.lzq");
        mul.lzq.MUL = 0;
     
        Ext.applyIf(me, {
        	items: [
					{  //0
					    xtype: 'combobox',							   
					    x:10,
					    y:0,
					    labelWidth:95,
					    fieldLabel: Share.T('查询条件'),
					    width: 190,                          
					    editable: false,
					    msgTarget:'side',
					    allowBlank:false,
                        blankText:Share.T('查询条件不能为空'),
					    valueField : 'value',
        				displayField : 'text',
    					listeners: {
                            change: {
                                fn: me.onSetDate,
                                scope: me
                            }
                        },
        				store : new Ext.data.JsonStore({
	            					proxy: { 
	                	                type: 'ajax', 
	                	                url : ctx + '/getDealFieldList',
	                	                params:{        	                	
	                	                },
	                	                reader: { 
	                	                    type: 'json', 
	                	                    totalProperty: '', 
	                	                    root: '' 
	                	                } 
	                	        }, 
	                	        fields:['text','value'], 
	                	        autoLoad:true
        				})
				},
				{  //1
				    xtype: 'combobox',						   
				    x:210,
				    y:0,
				    labelWidth:0,						
				    width: 80,                          
				    editable: false,	
				    hideTrigger : false,
				    msgTarget:'side',
				    allowBlank:false,
                    blankText:Share.T('字段逻辑判断符号不能为空'),
				    store:new Ext.data.Store({
						data:[{value:'>'},
						      {value:'='},
						      {value:'<'},
						      {value:'>='},
                              {value:'<='},
                              {value:'like'},
                              {value:'in'},
                              {value:'between'}
						     ],
				    fields:['value']
					}),
				valueField   : 'value',
				displayField : 'value',
					listeners: {
                        change: {
                            fn: me.onSetBetween,
                            scope: me
                        }
                    }	
			},
				{//2
 				    xtype: 'textfield',						   
 				    x:300,
 				    y:0,						
 				   msgTarget:'side',
				   allowBlank:false,
                   blankText:Share.T('查询值不能为空'),
 				    width: 130                          
             },
				{//3
                 xtype: 'datefield',
                 hidden:true,
                 format:'Y-m-d',
                 multiSelect: mul.lzq.MUL == 1 ? true : false,
                 x: 300,
                 y: 0,
                 msgTarget:'side',
                 editable:false,
				 allowBlank:false,
                 blankText:Share.T('日期不能为空'),
                 listeners: {
                     change: {
                         fn: me.onSetDate2,
                         scope: me
                     }
                 }
             },
 			{//4
                 xtype: 'label',
                 x: 451,
                 y: 5,
                 hidden:true,
                 width: 39,
                 text: 'and'
             },
             {//5
 				    xtype: 'textfield',						   
 				    x:490,
 				    y:0,						
 				   hidden:true,
 				   msgTarget:'side',
 				   allowBlank:false,
 				   blankText:Share.T('between尾值不能为空'),
 				   width: 130                          
          },
          {//6
              xtype: 'datefield',
              format:'Y-m-d',
              multiSelect: mul.lzq.MUL == 1 ? true : false,
              hidden:true,
              x: 490,
              y: 0,
              msgTarget:'side',
				   allowBlank:false,
              blankText:Share.T('日期不能为空')
          },
            {//7
                xtype: 'button',
                text: Share.T('删除字段'),
                x:650,
                y:0,
                handler:function(){             	
              		this.up('form').up('panel').remove(me,true);
                }
            }
		   ]                                            
         });
        me.callParent(arguments);
    },
    onSetBetween: function(field, newValue, oldValue, options) {
    	var PrintPanel = this;
 		var paramPanels = PrintPanel.getLayout().getLayoutItems();
    	if(newValue == 'between'){
     		paramPanels[4].show();
     		paramPanels[5].show();
    	}else{  //非between
    		paramPanels[4].hide();
     		paramPanels[5].hide();       
     		paramPanels[3].hide();
     		paramPanels[6].hide();       
    	}
    	if(paramPanels[0].getValue() == 'document_date' || paramPanels[0].getValue() == 'create_date' || paramPanels[0].getValue() == 'update_time' || paramPanels[0].getValue() == 'INVOICE_DATE' || paramPanels[0].getValue() == 'EXPRESS_DATE'){
 			paramPanels[2].hide();
 			paramPanels[3].show();
 			if(newValue == 'between'){
 				paramPanels[5].hide();
 				paramPanels[6].show();
 			}
 		}else{
 			paramPanels[3].hide();
 			paramPanels[2].show();
 			if(newValue == 'between'){
 				paramPanels[6].hide();
 				paramPanels[5].show();
 			}
 		}
    	if(newValue == 'in'){
    		mul.lzq.MUL = 1;
    	}
    },
    onSetDate: function(field, newValue, oldValue, options) {
    	Print_Main = Print_Main + ',' + newValue;
    	var PrintPanel = this;
    	var paramPanels = PrintPanel.getLayout().getLayoutItems();
    	if(newValue == 'document_date' || newValue == 'create_date' || newValue == 'update_time' || newValue == 'INVOICE_DATE' || newValue == 'EXPRESS_DATE'){
     		paramPanels[2].hide();
     		paramPanels[3].show();
     		if(paramPanels[1].getValue() == 'between'){
        		paramPanels[5].hide();
        		paramPanels[6].show();
        	}
    	}
    	else{  
    		paramPanels[3].hide();
     		paramPanels[2].show();
     		if(paramPanels[1].getValue() == 'between'){
     			paramPanels[6].hide();
     			paramPanels[5].show();
     		}
    	}
    },
    onSetDate2: function(field, newValue, oldValue, options) {
    	var PrintPanel = this;
    	var paramPanels = PrintPanel.getLayout().getLayoutItems();
    	if(paramPanels[1].getValue() == 'in'){
    		for(var i = 0;i<paramPanels[3].getRawValue().toString().split(',').length;i++){
    			if(paramPanels[3].getRawValue().toString().split(',')[i][4] != '-'){
    				return;
    			}else if(paramPanels[3].getRawValue().toString().split(',')[i][7] != '-'){
    				return;
    			}
    		}
    	}else{
    		if(paramPanels[3].getRawValue().toString()[4] != '-'){
    			return;
    		}else if(paramPanels[3].getRawValue().toString()[7] != '-'){
    			return;
    		}
    	}
    }
});